package com.taobaolite.order;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.taobaolite.item.ItemBody;
import com.taobaolite.order_has_items.OrderHasItems;

import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.List;


public class OrderBody {
//    @NotNull
//    @Min(value = 7000000)
    private Long orderId;
    @NotNull
    @Min(value = 900000000)
    private Long userId;
    @NotNull
    private OrderStatus status;
//    @NotNull
    private Timestamp time;
    @NotNull
    @JsonProperty(value = "order_has_items")
    private List<OrderItem> orderHasItems;

    public OrderBody() {}
    public OrderBody(Order order) {
        this.orderId = order.getOrderId();
        this.userId = order.getGuest().getGuestId();
        this.status = order.getStatus();
        this.time = order.getTime();
        this.orderHasItems = new ArrayList<>();
        for (OrderHasItems item : order.getItems() ) {
            orderHasItems.add(new OrderItem(item));
        }
    }

    public Long getOrderId() {
        return orderId;
    }

    public void setOrderId(Long orderId) {
        this.orderId = orderId;
    }

    public Long getUserId() {
        return userId;
    }

    public void setUserId(Long userId) {
        this.userId = userId;
    }

    public OrderStatus getStatus() {
        return status;
    }

    public void setStatus(OrderStatus status) {
        this.status = status;
    }

    public Timestamp getTime() {
        return time;
    }

    public void setTime(Timestamp time) {
        this.time = time;
    }

    public List<OrderItem> getOrderHasItems() {
        return orderHasItems;
    }

    public void setOrderHasItems(List<OrderItem> orderHasItems) {
        this.orderHasItems = orderHasItems;
    }
}

class OrderItem {
    private ItemBody item;
    private Long amount;

    public OrderItem() {}
    public OrderItem(OrderHasItems item) {
        this.item = new ItemBody(item.getOrderHasItemsPK().getItem());
        this.amount = item.getAmount();
    }

    public ItemBody getItem() {
        return item;
    }

    public void setItem(ItemBody item) {
        this.item = item;
    }

    public Long getAmount() {
        return amount;
    }

    public void setAmount(Long amount) {
        this.amount = amount;
    }
}

class PutItem {
    private Long userId;
    private Long orderId;
    private Short action;
    private OrderStatus status;

    public PutItem() {}

    public PutItem(Long userId, Long orderId, Short action, OrderStatus status) {
        this.userId = userId;
        this.orderId = orderId;
        this.action = action;
        this.status = status;
    }

    public OrderStatus getStatus() {
        return status;
    }

    public void setStatus(OrderStatus status) {
        this.status = status;
    }

    public Long getUserId() {
        return userId;
    }

    public void setUserId(Long userId) {
        this.userId = userId;
    }

    public Long getOrderId() {
        return orderId;
    }

    public void setOrderId(Long orderId) {
        this.orderId = orderId;
    }

    public Short getAction() {
        return action;
    }

    public void setAction(Short action) {
        this.action = action;
    }
}
